<!DOCTYPE html>












  


<html class="theme-next gemini use-motion" lang="zh-Hans">
<head><meta name="generator" content="Hexo 3.9.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
























<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css?v=4.7.0">

<link rel="stylesheet" href="/css/main.css?v=7.1.2">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=7.1.2">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=7.1.2">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=7.1.2">


  <link rel="mask-icon" href="/images/logo.svg?v=7.1.2" color="#222">







<script id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Gemini',
    version: '7.1.2',
    sidebar: {"position":"left","display":"post","offset":12,"onmobile":false,"dimmer":false},
    back2top: true,
    back2top_sidebar: false,
    fancybox: false,
    fastclick: false,
    lazyload: false,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>


  




  <meta name="description" content="一、为什么需要使用线程池 线程创建和销毁的开销非常高：频繁的创建和销毁线程需要消耗时间，会使响应变慢；同时消耗计算资源。 资源耗尽：空闲的线程会占用内存，会给垃圾回收带来压力，线程竞争CPU也会产生性能开销，线程池可合理管理空闲线程 稳定性：在一定范围内，增加线程可以提升系统的处理能力，如果超过这个范围，继续创建线程只会降低执行速度，甚至导致系统OOM,线程池即可以通过程序控制线程数。  二、几个">
<meta name="keywords" content="java">
<meta property="og:type" content="article">
<meta property="og:title" content="java多线程之ThreadPoolExcutor">
<meta property="og:url" content="http://www.wuxiantao123.cn/2019/06/18/java多线程之ThreadPoolExcutor/index.html">
<meta property="og:site_name" content="费曼的门徒">
<meta property="og:description" content="一、为什么需要使用线程池 线程创建和销毁的开销非常高：频繁的创建和销毁线程需要消耗时间，会使响应变慢；同时消耗计算资源。 资源耗尽：空闲的线程会占用内存，会给垃圾回收带来压力，线程竞争CPU也会产生性能开销，线程池可合理管理空闲线程 稳定性：在一定范围内，增加线程可以提升系统的处理能力，如果超过这个范围，继续创建线程只会降低执行速度，甚至导致系统OOM,线程池即可以通过程序控制线程数。  二、几个">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2019-07-02T11:21:32.678Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="java多线程之ThreadPoolExcutor">
<meta name="twitter:description" content="一、为什么需要使用线程池 线程创建和销毁的开销非常高：频繁的创建和销毁线程需要消耗时间，会使响应变慢；同时消耗计算资源。 资源耗尽：空闲的线程会占用内存，会给垃圾回收带来压力，线程竞争CPU也会产生性能开销，线程池可合理管理空闲线程 稳定性：在一定范围内，增加线程可以提升系统的处理能力，如果超过这个范围，继续创建线程只会降低执行速度，甚至导致系统OOM,线程池即可以通过程序控制线程数。  二、几个">





  
  
  <link rel="canonical" href="http://www.wuxiantao123.cn/2019/06/18/java多线程之ThreadPoolExcutor/">



<script id="page.configurations">
  CONFIG.page = {
    sidebar: "",
  };
</script>

  <title>java多线程之ThreadPoolExcutor | 费曼的门徒</title>
  












  <noscript>
  <style>
  .use-motion .motion-element,
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-title { opacity: initial; }

  .use-motion .logo,
  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">费曼的门徒</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
    
      
        <h1 class="site-subtitle" itemprop="description">Feynman follower</h1>
      
    
    
  </div>

  <div class="site-nav-toggle">
    <button aria-label="切换导航栏">
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>



<nav class="site-nav">
  
    <ul id="menu" class="menu">
      
        
        
        
          
          <li class="menu-item menu-item-home">

    
    
    
      
    

    

    <a href="/" rel="section"><i class="menu-item-icon fa fa-fw fa-home"></i> <br>首页</a>

  </li>
        
        
        
          
          <li class="menu-item menu-item-tags">

    
    
    
      
    

    

    <a href="/tags/" rel="section"><i class="menu-item-icon fa fa-fw fa-tags"></i> <br>标签</a>

  </li>
        
        
        
          
          <li class="menu-item menu-item-categories">

    
    
    
      
    

    

    <a href="/categories/" rel="section"><i class="menu-item-icon fa fa-fw fa-th"></i> <br>分类</a>

  </li>
        
        
        
          
          <li class="menu-item menu-item-archives">

    
    
    
      
    

    

    <a href="/archives/" rel="section"><i class="menu-item-icon fa fa-fw fa-archive"></i> <br>归档</a>

  </li>
        
        
        
          
          <li class="menu-item menu-item-备忘录">

    
    
    
      
    

    

    <a href="/books" rel="section"><i class="menu-item-icon fa fa-fw fa-book"></i> <br>备忘录</a>

  </li>
        
        
        
          
          <li class="menu-item menu-item-计划待办">

    
    
    
      
    

    

    <a href="/todolist" rel="section"><i class="menu-item-icon fa fa-fw fa-calendar"></i> <br>计划待办</a>

  </li>
        
        
        
          
          <li class="menu-item menu-item-about">

    
    
    
      
    

    

    <a href="/about/" rel="section"><i class="menu-item-icon fa fa-fw fa-user"></i> <br>关于</a>

  </li>

      
      
    </ul>
  

  

  
</nav>



  



</div>
    </header>

    
  
  

  

  <a href="https://github.com/peach-boy" class="github-corner" title="Follow me on GitHub" aria-label="Follow me on GitHub" rel="noopener" target="_blank"><svg width="80" height="80" viewbox="0 0 250 250" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"/><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"/><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"/></svg></a>



    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          
            

          
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://www.wuxiantao123.cn/2019/06/18/java多线程之ThreadPoolExcutor/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Thomas Wu">
      <meta itemprop="description" content="人帅也要多读书，多学习，多运动">
      <meta itemprop="image" content="/images/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="费曼的门徒">
    </span>

    
      <header class="post-header">

        
        
          <h2 class="post-title" itemprop="name headline">java多线程之ThreadPoolExcutor

              
            
          </h2>
        

        <div class="post-meta">
          <span class="post-time">

            
            
            

            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              

              
                
              

              <time title="创建时间：2019-06-18 16:53:26" itemprop="dateCreated datePublished" datetime="2019-06-18T16:53:26+08:00">2019-06-18</time>
            

            
              

              
                
                <span class="post-meta-divider">|</span>
                

                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                
                  <span class="post-meta-item-text">更新于</span>
                
                <time title="修改时间：2019-07-02 19:21:32" itemprop="dateModified" datetime="2019-07-02T19:21:32+08:00">2019-07-02</time>
              
            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing"><a href="/categories/java多线程/" itemprop="url" rel="index"><span itemprop="name">java多线程</span></a></span>

                
                
              
            </span>
          

          
            
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h2 id="一、为什么需要使用线程池"><a href="#一、为什么需要使用线程池" class="headerlink" title="一、为什么需要使用线程池"></a>一、为什么需要使用线程池</h2><ul>
<li><strong>线程创建和销毁的开销非常高</strong>：频繁的创建和销毁线程需要消耗时间，会使响应变慢；同时消耗计算资源。</li>
<li><strong>资源耗尽</strong>：空闲的线程会占用内存，会给垃圾回收带来压力，线程竞争CPU也会产生性能开销，线程池可合理管理空闲线程</li>
<li><strong>稳定性</strong>：在一定范围内，增加线程可以提升系统的处理能力，如果超过这个范围，继续创建线程只会降低执行速度，甚至导致系统OOM,线程池即可以通过程序控制线程数。</li>
</ul>
<h2 id="二、几个常用线程池"><a href="#二、几个常用线程池" class="headerlink" title="二、几个常用线程池"></a>二、几个常用线程池</h2><p>首先看下线程池的构造函数：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line">/**</span><br><span class="line">    public ThreadPoolExecutor(int corePoolSize,</span><br><span class="line">                              int maximumPoolSize,</span><br><span class="line">                              long keepAliveTime,</span><br><span class="line">                              TimeUnit unit,</span><br><span class="line">                              BlockingQueue&lt;Runnable&gt; workQueue,</span><br><span class="line">                              ThreadFactory threadFactory,</span><br><span class="line">                              RejectedExecutionHandler handler) &#123;</span><br><span class="line">        if (corePoolSize &lt; 0 ||</span><br><span class="line">            maximumPoolSize &lt;= 0 ||</span><br><span class="line">            maximumPoolSize &lt; corePoolSize ||</span><br><span class="line">            keepAliveTime &lt; 0)</span><br><span class="line">            throw new IllegalArgumentException();</span><br><span class="line">        if (workQueue == null || threadFactory == null || handler == null)</span><br><span class="line">            throw new NullPointerException();</span><br><span class="line">        this.acc = System.getSecurityManager() == null ?</span><br><span class="line">                null :</span><br><span class="line">                AccessController.getContext();</span><br><span class="line">        this.corePoolSize = corePoolSize;</span><br><span class="line">        this.maximumPoolSize = maximumPoolSize;</span><br><span class="line">        this.workQueue = workQueue;</span><br><span class="line">        this.keepAliveTime = unit.toNanos(keepAliveTime);</span><br><span class="line">        this.threadFactory = threadFactory;</span><br><span class="line">        this.handler = handler;</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure>

<ol>
<li><p><strong>newFixedThreadPool</strong>:将创建一个<strong>长度固定的线程池</strong>，每当新提交一个任务时就创建一个新线程，直到达到线程池的最大数量，这时线程池的大小不在变化（如果某个线程发生未预期的Exception而结束，那么线程池会补充一个新线程）。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">public static ExecutorService newFixedThreadPool(int nThreads, ThreadFactory threadFactory) &#123;</span><br><span class="line">       return new ThreadPoolExecutor(nThreads, nThreads,</span><br><span class="line">                                     0L, TimeUnit.MILLISECONDS,</span><br><span class="line">                                     new LinkedBlockingQueue&lt;Runnable&gt;(),</span><br><span class="line">                                     threadFactory);</span><br><span class="line">   &#125;</span><br></pre></td></tr></table></figure>
</li>
<li><p><strong>newCachedThreadPool</strong>:将创建一个<strong>可缓存的线程池</strong>，如果有线程空闲，会回收空闲线程；如果任务增加时，可添加新线程，线程池的规模不存在任何界限。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">public static ExecutorService newCachedThreadPool() &#123;</span><br><span class="line">       return new ThreadPoolExecutor(0, Integer.MAX_VALUE,</span><br><span class="line">                                     60L, TimeUnit.SECONDS,</span><br><span class="line">                                     new SynchronousQueue&lt;Runnable&gt;());</span><br><span class="line">   &#125;</span><br></pre></td></tr></table></figure>
</li>
<li><p><strong>newSingleThreadPool</strong>:将创建一个<strong>单线程的线程池</strong>，如果线程异常结束，将创建另一个线程来替代；阻塞队列为LinkedBlockingQueue，提交的任务可按照顺序执行</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">public static ExecutorService newSingleThreadExecutor() &#123;</span><br><span class="line">        return new FinalizableDelegatedExecutorService</span><br><span class="line">            (new ThreadPoolExecutor(1, 1,</span><br><span class="line">                                    0L, TimeUnit.MILLISECONDS,</span><br><span class="line">                                    new LinkedBlockingQueue&lt;Runnable&gt;()));</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure>
</li>
<li><p><strong>newScheduledThreadPool</strong>： 创建了一个<strong>固定长度的线程池,而且以延迟或定时的方式来执行任务</strong>,类似于Timer。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">public ScheduledThreadPoolExecutor(int corePoolSize,</span><br><span class="line">                                   ThreadFactory threadFactory) &#123;</span><br><span class="line">    super(corePoolSize, Integer.MAX_VALUE, 0, NANOSECONDS,</span><br><span class="line">          new DelayedWorkQueue(), threadFactory);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

</li>
</ol>
<h2 id="三、线程池的六个重要参数："><a href="#三、线程池的六个重要参数：" class="headerlink" title="三、线程池的六个重要参数："></a>三、线程池的六个重要参数：</h2><ol>
<li><strong>corePoolSize</strong>：核心线程数<ul>
<li>核心线程会一直存活，及时没有任务需要执行</li>
<li>线程数 &lt; corePoolSize时，即使有线程空闲，线程池也会优先创建新线程处理</li>
<li>设置allowCoreThreadTimeout=true（默认false）时，核心线程会超时关闭</li>
</ul>
</li>
<li><strong>queueCapacity</strong>：任务队列容量（阻塞队列）<br> 当核心线程数达到最大时，新任务会放在队列中排队等待执行</li>
<li><strong>maxPoolSize</strong>：最大线程数<ul>
<li>线程数&gt;=corePoolSize，且任务队列已满时。线程池会创建新线程来处理任务</li>
<li>线程数=maxPoolSize，且任务队列已满时，线程池会拒绝处理任务而抛出异常</li>
</ul>
</li>
<li><strong>keepAliveTime</strong>：线程空闲时间<ul>
<li>当线程空闲时间达到keepAliveTime时，线程会退出，直到线程数量=corePoolSize</li>
<li>如果allowCoreThreadTimeout=true，则会直到线程数量=0</li>
</ul>
</li>
<li><strong>allowCoreThreadTimeout</strong>：允许核心线程超时</li>
<li><strong>rejectedExecutionHandler</strong>：任务拒绝处理器,两种情况会拒绝处理任务：<ul>
<li>当线程数已经达到maxPoolSize，切队列已满，会拒绝新任务</li>
<li>当线程池被调用shutdown()后，会等待线程池里的任务执行完毕，再shutdown。如果在调用shutdown()和线程池真正shutdown之间提交任务，会拒绝新任务</li>
<li>线程池会调用rejectedExecutionHandler来处理这个任务。如果没有设置默认是AbortPolicy，会抛出异常</li>
</ul>
</li>
<li>拒绝策略：<ul>
<li>AbortPolicy 直接抛出一个RejectedExecutionException，这也是JDK默认的拒绝策略</li>
<li>CallerRunsPolicy 尝试直接运行被拒绝的任务，如果线程池已经被关闭了，任务就被丢弃了</li>
<li>DiscardPolicy 不能执行的任务将被删除</li>
<li>DiscardOldestPolicy 移除最晚的那个没有被处理的任务，然后执行被拒绝的任务。同样，如果线程池已经被关闭了，任务就被丢弃了</li>
<li>自定义：实现RejectedExecutionHandler接口，可自定义处理器</li>
</ul>
</li>
</ol>
<h2 id="四、ThreadPoolExecutor执行顺序："><a href="#四、ThreadPoolExecutor执行顺序：" class="headerlink" title="四、ThreadPoolExecutor执行顺序："></a>四、ThreadPoolExecutor执行顺序：</h2><pre><code>线程池按以下行为执行任务</code></pre><ol>
<li>currentThreadNum &lt; corePoolSize-&gt;创建线程。</li>
<li>corePoolSize =&lt; currentThreadNum ，对列未满，加入队列。</li>
<li>corePoolSize =&lt; currentThreadNum &lt;maxPoolSize ，且任务队列已满,创建线程</li>
<li>corePoolSize =&lt; currentThreadNum &amp;&amp;currentThreadNum&gt;=maxPoolSize ,且任务队列已满,创建线程，抛出异常，拒绝任务</li>
</ol>
<h2 id="五、如何设置参数"><a href="#五、如何设置参数" class="headerlink" title="五、如何设置参数"></a>五、如何设置参数</h2><ul>
<li>默认值<br>corePoolSize=1<br>queueCapacity=Integer.MAX_VALUE<br>maxPoolSize=Integer.MAX_VALUE<br>keepAliveTime=60s<br>allowCoreThreadTimeout=false<br>rejectedExecutionHandler=AbortPolicy()</li>
<li>如何来设置<ol>
<li>需要根据几个值来决定</li>
</ol>
<ul>
<li>tasks ：每秒的任务数，假设为500~1000</li>
<li>taskcost：每个任务花费时间，假设为0.1s</li>
<li>responsetime：系统允许容忍的最大响应时间，假设为1s</li>
</ul>
<ol start="2">
<li>做几个计算</li>
</ol>
<ul>
<li>corePoolSize = 每秒需要多少个线程处理？<br>threadcount = tasks/(1/taskcost) =tasks<em>taskcout =  (500~1000)</em>0.1 = 50~100 个线程。corePoolSize设置应该大于50<br>根据8020原则，如果80%的每秒任务数小于800，那么corePoolSize设置为80即可</li>
<li>queueCapacity = (coreSizePool/taskcost)<em>responsetime<br>计算可得 queueCapacity = 80/0.1</em>1 = 80。意思是队列里的线程可以等待1s，超过了的需要新开线程来执行<br>切记不能设置为Integer.MAX_VALUE，这样队列会很大，线程数只会保持在corePoolSize大小，当任务陡增时，不能新开线程来执行，响应时间会随之陡增。</li>
<li>maxPoolSize = (max(tasks)- queueCapacity)/(1/taskcost)<br>计算可得 maxPoolSize = (1000-80)/10 = 92<br>（最大任务数-队列容量）/每个线程每秒处理能力 = 最大线程数</li>
<li>rejectedExecutionHandler：根据具体情况来决定，任务不重要可丢弃，任务重要则要利用一些缓冲机制来处理</li>
<li>keepAliveTime和allowCoreThreadTimeout采用默认通常能满足</li>
</ul>
</li>
</ul>

      
    </div>

    

    
    
    

    

    
      
    
    

    

    <footer class="post-footer">
      
        
          
        
        <div class="post-tags">
          
            <a href="/tags/java/" rel="tag"># java</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2019/06/18/关于提升工作效率的一点思考/" rel="next" title="关于提升工作效率的一点思考">
                <i class="fa fa-chevron-left"></i> 关于提升工作效率的一点思考
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2019/06/18/spring常用接口之BeanpostProccesser/" rel="prev" title="spring常用接口之BeanpostProccesser">
                spring常用接口之BeanpostProccesser <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>


  </div>


          </div>
          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image" src="/images/avatar.jpg" alt="Thomas Wu">
            
              <p class="site-author-name" itemprop="name">Thomas Wu</p>
              <div class="site-description motion-element" itemprop="description">人帅也要多读书，多学习，多运动</div>
          </div>

          
            <nav class="site-state motion-element">
              
                <div class="site-state-item site-state-posts">
                
                  <a href="/archives/">
                
                    <span class="site-state-item-count">24</span>
                    <span class="site-state-item-name">日志</span>
                  </a>
                </div>
              

              
                
                
                <div class="site-state-item site-state-categories">
                  
                    
                      <a href="/categories/">
                    
                  
                    
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                    <span class="site-state-item-count">9</span>
                    <span class="site-state-item-name">分类</span>
                  </a>
                </div>
              

              
                
                
                <div class="site-state-item site-state-tags">
                  
                    
                      <a href="/tags/">
                    
                  
                    
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                    <span class="site-state-item-count">6</span>
                    <span class="site-state-item-name">标签</span>
                  </a>
                </div>
              
            </nav>
          

          

          

          
            <div class="links-of-author motion-element">
              
                <span class="links-of-author-item">
                  
                  
                    
                  
                  
                    
                  
                  <a href="https://github.com/peach-boy" title="GitHub &rarr; https://github.com/peach-boy" rel="noopener" target="_blank"><i class="fa fa-fw fa-github"></i>GitHub</a>
                </span>
              
                <span class="links-of-author-item">
                  
                  
                    
                  
                  
                    
                  
                  <a href="/1414924381@qq.com" title="E-Mail &rarr; 1414924381@qq.com"><i class="fa fa-fw fa-envelope"></i>E-Mail</a>
                </span>
              
            </div>
          

          

          
          
            <div class="links-of-blogroll motion-element links-of-blogroll-block">
              <div class="links-of-blogroll-title">
                <i class="fa  fa-fw fa-link"></i>
                友情链接
              </div>
              <ul class="links-of-blogroll-list">
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.cnblogs.com/xrq730/" title="https://www.cnblogs.com/xrq730/" rel="noopener" target="_blank">五月的仓颉</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.w3cschool.cn/architectroad/" title="https://www.w3cschool.cn/architectroad/" rel="noopener" target="_blank">沈剑架构师之路</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://crossoverjie.top/" title="https://crossoverjie.top/" rel="noopener" target="_blank">crossoverjie</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.jianshu.com/u/2766e4cfc391" title="https://www.jianshu.com/u/2766e4cfc391" rel="noopener" target="_blank">高广超</a>
                  </li>
                
              </ul>
            </div>
          

          
            
          
          

        </div>
      </div>

      
      <!--noindex-->
        <div class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
            
            
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#一、为什么需要使用线程池"><span class="nav-number">1.</span> <span class="nav-text">一、为什么需要使用线程池</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#二、几个常用线程池"><span class="nav-number">2.</span> <span class="nav-text">二、几个常用线程池</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#三、线程池的六个重要参数："><span class="nav-number">3.</span> <span class="nav-text">三、线程池的六个重要参数：</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#四、ThreadPoolExecutor执行顺序："><span class="nav-number">4.</span> <span class="nav-text">四、ThreadPoolExecutor执行顺序：</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#五、如何设置参数"><span class="nav-number">5.</span> <span class="nav-text">五、如何设置参数</span></a></li></ol></div>
            

          </div>
        </div>
      <!--/noindex-->
      

      

    </div>
  </aside>
  


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2019</span>
  <span class="with-love" id="animate">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Thomas Wu</span>

  

  
</div>









        








        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

    

    
  </div>

  

<script>
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>


























  
  <script src="/lib/jquery/index.js?v=3.4.1"></script>

  
  <script src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>


  


  <script src="/js/utils.js?v=7.1.2"></script>

  <script src="/js/motion.js?v=7.1.2"></script>



  
  


  <script src="/js/affix.js?v=7.1.2"></script>

  <script src="/js/schemes/pisces.js?v=7.1.2"></script>




  
  <script src="/js/scrollspy.js?v=7.1.2"></script>
<script src="/js/post-details.js?v=7.1.2"></script>



  


  <script src="/js/next-boot.js?v=7.1.2"></script>


  

  

  

  


  


  




  

  

  

  

  

  

  

  

  

  

  

  

  

  

</body>
</html>
